﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ClassMgr.aspx.cs" Inherits="InformationSystem.WebSite.Module.StuMgr.ClassMgr" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var addClass = function () {
                var grid = GridPanel1;
                //有脏数据，不允许再次新增行
                if (grid.isDirty()) return;
                grid.getRowEditor().stopEditing();

                grid.insertRecord();
                grid.getSelectionModel().selectRow(0);
                grid.getRowEditor().startEditing(0);
            }

            var removeClass = function () {
                var grid = GridPanel1;
                grid.getRowEditor().stopEditing();
                grid.deleteSelected();
                classListStore.save();
            }

            function callback() {
                parent.ResizeFrameHeight(GridPanel1.getHeight());
            }

            function AfterEdit() {
                var s = GridPanel1.getSelectionModel().getSelections();
                var total = GridPanel1.store.getTotalCount()
                for (var i = 1; i < total - 1; i++) {
                    if (GridPanel1.getView().getCell(i, 0).innerText == s[0].data.classid) {
                        s[0].data.classid = '';
                        Ext.Msg.alert('信息：', '班级ID冲突！');
                        return;
                    }
                }
                GridPanel1.save();
            }
        </script>
    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
        <Listeners>
            <DocumentReady Fn="callback()" />
        </Listeners>
    </ext:ResourceManager>
    <ext:GridPanel ID="GridPanel1" runat="server" Height="400" Title="班级管理" Layout="ContainerLayout">
        <Store>
            <ext:Store ID="classListStore" runat="server" OnBeforeRecordUpdated="BeforeRecordUpdated"
                AutoLoad="true" OnBeforeRecordDeleted="BeforeRecordDeleted" OnBeforeRecordInserted="BeforeRecordInserted"
                OnAfterStoreChanged="AfterStoreChanged">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="classid" Mapping="ClassID" Type="String" />
                            <ext:RecordField Name="classname" Mapping="ClassName" Type="String" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Store>
        <Plugins>
            <ext:RowEditor ID="RowEditor1" runat="server" SaveText="保存" CancelText="取消" CommitChangesText=""
                MonitorValid="true" ErrorSummary="false">
                <Listeners>
                    <AfterEdit Handler="AfterEdit()" />
                </Listeners>
            </ext:RowEditor>
        </Plugins>
        <TopBar>
            <ext:Toolbar ID="Toolbar1" runat="server">
                <Items>
                    <ext:Button ID="Button1" runat="server" Text="新增" Icon="Add">
                        <Listeners>
                            <Click Fn="addClass" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button2" runat="server" Text="删除" Icon="Delete">
                        <Listeners>
                            <Click Fn="removeClass" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button3" runat="server" Text="刷新" Icon="Reload">
                        <DirectEvents>
                            <Click OnEvent="btnRefresh_Click">
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Items>
            </ext:Toolbar>
        </TopBar>
        <BottomBar>
            <ext:StatusBar runat="server" Text="双击记录进行编辑">
            </ext:StatusBar>
        </BottomBar>
        <SelectionModel>
            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
            </ext:RowSelectionModel>
        </SelectionModel>
        <ColumnModel>
            <Columns>
                <ext:Column ColumnID="classid" Header="班级编号" DataIndex="classid" Width="180" Sortable="true">
                    <Editor>
                        <ext:TextField ID="TextField1" runat="server" AllowBlank="false">
                            <Listeners>
                                <BeforeShow Handler="javascript:if(TextField1.value!=''){document.getElementById('TextField1').style.display='none';}else{document.getElementById('TextField1').style.display='';}" />
                            </Listeners>
                        </ext:TextField>
                    </Editor>
                </ext:Column>
                <ext:Column ColumnID="classname" Header="班级名称" DataIndex="classname" Width="450">
                    <Editor>
                        <ext:TextField ID="TextField2" runat="server" AllowBlank="false" />
                    </Editor>
                </ext:Column>                
            </Columns>
        </ColumnModel>
        <Listeners>
        </Listeners>
        <DirectEvents>
        </DirectEvents>
    </ext:GridPanel>
    </form>
</body>
</html>
